package com.srt.controller;


import com.srt.model.Catalog;
import com.srt.service.CatalogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author rd06
 * @since 2021-03-29
 */
@Controller
public class CatalogController {
    @Autowired
    private CatalogService catalogService;

    @GetMapping("/")
    public String list(HttpServletRequest request) {
        List<Catalog> catalogList = catalogService.lambdaQuery().eq(Catalog::getIsDelete, 0).list();
        request.setAttribute("catalogList", catalogList);
        return "catalog_list";
    }

    @GetMapping("/catalog/to_save")
    public String toSave() {
        return "catalog_save";
    }

    @GetMapping("/catalog/del/{id}")
    public String del(@PathVariable("id")Long id) {
        catalogService.removeById(id);
        return "redirect:/";
    }


}

